﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Globalization;
using System.Windows.Data;

namespace Frontend
{
    [ValueConversion(typeof(RefreshStatus), typeof(Visibility))]
    class RefreshStatusToVisibilityConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter == null)
            {
                return Visibility.Visible;
            }

            if (targetType != typeof(Visibility))
            {
                throw new ArgumentException("Can convert only to Visibility type");
            }

            if (parameter.GetType() != typeof(RefreshStatus))
            {
                throw new ArgumentException("Custom parameter: can convert only from RefreshStatus type");
            }

            if (value.GetType() != typeof(RefreshStatus))
            {
                throw new ArgumentException("Value: can convert only from RefreshStatus type");
            }

            RefreshStatus expected = (RefreshStatus)parameter;
            RefreshStatus current = (RefreshStatus)value;

            Visibility visibility = Visibility.Collapsed;
            if (expected == current)
            {
                visibility = Visibility.Visible;
            }
            return visibility;
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
